package com.kp.fintech.admin.service.impl;

import com.kp.fintech.admin.dao.SysHomeMapper;
import com.kp.fintech.admin.model.SysHome;
import com.kp.fintech.admin.service.SysHomeService;
import com.kp.fintech.core.page.MybatisPageHelper;
import com.kp.fintech.core.page.PageRequest;
import com.kp.fintech.core.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;

@Service
public class SysHomeServiceImpl implements SysHomeService {

    @Autowired
    SysHomeMapper sysHomeMapper ;

    @Transactional
    @Override
    public int save(SysHome record) {
        Long id = null;
        if (record.getId() == null || record.getId() == 0) {
            // 新增Home信息
            sysHomeMapper.insertSelective(record);
            id = record.getId();
        } else {
            // 更新Home信息
            sysHomeMapper.updateByPrimaryKeySelective(record);
        }
        // 更新用户角色
        if (id != null && id == 0) {
            return 1;
        }

        return 0;
    }

    @Override
    public int delete(SysHome record) {
        return sysHomeMapper.deleteByPrimaryKey(record.getId());
    }

    @Override
    public int delete(List<SysHome> records) {
        for(SysHome record:records) {
            delete(record);
        }
        return 1;
    }

    @Override
    public SysHome findById(Long id) {
        return sysHomeMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageResult findPage(PageRequest pageRequest) {
        return MybatisPageHelper.findPage(pageRequest, sysHomeMapper);
    }

}
